package com.turtle3d.user.grammars;

import com.turtle3d.formallanguage.grammar.Grammar;
import com.turtle3d.formallanguage.grammar.parser.SimpleParser;
import com.turtle3d.formallanguage.symbol.Method;
import com.turtle3d.formallanguage.symbol.Symbol;
import com.turtle3d.formallanguage.symbol.SymbolClass;
import com.turtle3d.formallanguage.symbol.SymbolFactory;

public class IFSFern extends Grammar
{

	@Override
	public void define()
	{	
		
		setAxiom(SymbolFactory.getSymbolFactory().createSymbolofClass("B"));
		setDefaultParameter("turnAngle", 60f);
		setDefaultParameter("turnAngle2", 3f);
		setDefaultParameter("distance", 2f);
		setDefaultParameter("radius", 0.06f);
		setDefaultParameter("pitchAngle", 5f);
		setDefaultParameter("leafSize", 10f);
		setDefaultParameter("scaleMultiplier", 0.78f);
		
		SymbolClass turnAngle2 = new SymbolClass("-", "-(2)");		
		turnAngle2.addMethod(new Method(){
			public boolean calculate(Symbol removedSymbol, Symbol calculatedSymbol)
			{
				calculatedSymbol.setParameter("turnAngle", getDefaultParameter("turnAngle2"));
				
				return true;				
			}
		});				
		SymbolFactory.getSymbolFactory().registerSymbolClass(turnAngle2);
		
		SymbolClass mirror = new SymbolClass("S","S(mirror)");		
		mirror.addMethod(new Method(){
			public boolean calculate(Symbol removedSymbol, Symbol calculatedSymbol)
			{				
				calculatedSymbol.setParameter("scaleMultiplierX", -1f);				
				calculatedSymbol.setParameter("scaleMultiplierY", 1f);
				calculatedSymbol.setParameter("scaleMultiplierZ", 1f);
				return true;				
			}
		});				
		SymbolFactory.getSymbolFactory().registerSymbolClass(mirror);				
						
		String fernModule = "[-S(mirror)SSSB]-(2)/SF[+SSSB]-(2)/SF";
		String fernString = "";
		for(int i=0;i<5;i++)
			fernString+=fernModule;
		
		//addProduction(SimpleParser.parseProduction("B->F[+SSSB]-(2)/SF[-S(mirror)SSSB]-(2)/SF[+SSSB]-(2)/SF[-S(mirror)SSSB]-(2)/SF[+SSSB]-(2)/SF[-S(mirror)SSSB]-(2)/SF[+SSSB]-(2)/SF[-S(mirror)SSSB]-(2)/SF[+SSSB]-(2)/SF[-S(mirror)SSSB]-(2)/SF[+SSSB]-(2)/SF[-S(mirror)SSSB]-(2)/SF[+SSSB]-(2)/SF"));
		addProduction(SimpleParser.parseProduction("B->F[+SSSB]-(2)/SF"+fernString));

	}

}
